#os clipboard stuff
from Tkinter import Tk

def PasteToClipboard(data):
    r = Tk()
    r.withdraw()
    r.clipboard_clear()
    r.clipboard_append(data)
    r.destroy()

def Prices(p):
    assert(len(p) == 4)
    d = {'Oxen': p[0], 'Clothes': p[1], 'Bullets':p[2],
         'Wheels':p[1], 'Axles':p[1], 'Tounges':p[1], 'Food':p[3]}
    strs = ['.set(Item.{0},{1})'.format(k.upper(), v) for k,v in d.items()]
    return 'new ItemVec()' + ''.join(strs)        

def RiverData(r):
    r = r.split()
    f = 'ferry' in r
    i = 'indians' in r
    f,i = [str(b).lower() for b in (f,i)] #java bools are lowercase
    return 'new LocationRiverData({0},{1},{2:.2})'.format(f,i,float(r[0]))

def Segment(t):
    return 'new TrailSegment("{0}",{1})'.format(*t)

def Location(name, prices, riverdata, *exits):
    p = Prices(prices) if prices else 'null'
    r = RiverData(riverdata) if riverdata else 'null'

    nnargs = [p, r] + map(Segment, exits)
    return 'templocations.put("{0}", new Location("{0}",{1}));'.format(
        name, ','.join(nnargs))

data = [("Independence", (20,10,2,0.2), [], ("Kansas River", 102))] 
data += [("Kansas River", [], "5.4 ferry", ("Big Blue River", 83))]
data += [("Big Blue River", [], "3.0", ("Fort Kearney", 120))]
data += [("Fort Kearney", (25,12.5,2.4,0.25), [], ("Chimney Rock", 250))] 
data += [("Chimney Rock", [], [], ("Fort Laramie", 86))]
data += [("Fort Laramie", (30,15,3,0.3), [], ("Independence Rock", 190))] 
data += [("Independence Rock", [], [], ("South Pass", 102))]
data += [("South Pass", [], [], ("Fort Bridger", 57), ("Green River", 125))]
data += [("Fort Bridger", (35,17.5,3.4,0.35), [], ("Green River", 162))] 
data += [("Green River", [], "40.6 ferry", ("Soda Springs", 144))]
data += [("Soda Springs", [], [], ("Fort Hall", 57))]
data += [("Fort Hall", (40,20,4,0.4), [], ("Snake River", 182))] 
data += [("Snake River", [], "12.0 indians", ("Fort Boise", 114))]
data += [("Fort Boise", (45,22.5,4.4,0.45), [], ("Grande Ronde", 160))] 
data += [("Grande Ronde", [], [], ("Fort Walla Walla", 55), ("The Dalles", 125))]
data += [("Fort Walla Walla", (50,25,5,0.5), [], ("The Dalles", 120))] 
data += [("The Dalles", [], [], ("Willamette Valley", 100))]
data += [("Willamette Valley", [], [])]


code = '\n'.join([Location(*args) for args in data])
PasteToClipboard(code)

'''
Independence
20,10,2,10,10,10,0.2
-> KR 102

Kansas River 
ferry
639, 7.2
635 6.7
631 6.2
628 5.7
625 5.4
622 5.0
620 4.7
618 4.4
616 4.2
614 3.9
613 3.8
-> BBR 83

Big Blue River
228 3.1
227 3.0
227 2.9
-> FK 120

Fort Kearney
25,12.5,2.4,12.5,12.5,12.5,0.25
-> 250

Chimney Rock
->86

Fort Laramie
30,15,3,15,15,15,0.3
->190

Independence Rock
-> 102

South Pass
-> GR 125
-> FB 57

Fort Bridger
35, 17.5, 3.4, ***, 0.35
-> GR 162

Green River
ferry
405 40.7
404 40.6
404 40.5
-> SS 144

Soda Springs
-> 57

Fort Hall
40,20,4,20,20,20,0.4
-> 182

Snake River
indian
1000 12.0
1000 12.0
1000 12.0
-> 114

Fort Boise
45,22.5,4.4,22.5,22.5,22.5,0.45
-> 160

Grande Ronde
-> TD 125
-> FWW 55

Fort Walla Walla
50, 25, 5, ***, 0.5
-> TD 120

The Dalles
-> WV 100
-> rafting
'''
















